const autoprefixer = require('autoprefixer')
const pxtorem = require('postcss-pxtorem')
const TerserPlugin = require('terser-webpack-plugin')
// npm install terser-webpack-plugin --save-dev
// npm install babel-plugin-transform-remove-console --save-dev
const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  //publicPath: '/app',
  assetsDir: 'static', //  outputDir的静态资源(js、css、img、fonts)目录
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  transpileDependencies: true,
  lintOnSave: false,
  productionSourceMap: false, //不输出map文件
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      // 为生产环境修改配置...
      config.plugins.push(
        //去掉打包之后的打印
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: false,
              pure_funcs: ['console.log'], // 移除console
            },
          },
        })
      )
    } else {
      // 为开发环境修改配置...
    }
  },
  css: {
    loaderOptions: {
      postcss: {
        postcssOptions: {
          plugins: [
            autoprefixer(),
            pxtorem({
              rootValue: 37.5,
              propList: ['*'],
            }),
          ],
        },
      },
    },
  },
})
